/*
 * Copyright (C) 2011 Macambira Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.googlecode.control;

import com.googlecode.entity.Departamento;
import java.util.LinkedList;
import java.util.List;

/**
 * Classe responsavel por realizar o CRUD de departamento
 *
 * @version 0.2 28 Set 2011
 * @author Ihago Alencar | ihago.alencar@dce.ufpb.br
 */
public class ControlDepartamento {

    private List<Departamento> departamentos;

    public ControlDepartamento() {
        this.departamentos = new LinkedList<Departamento>();
    }

    public void addDepartamento(Departamento departamento) {
        this.departamentos.add(departamento);
    }

    public Departamento getDepartamentoNome(String nome) {
        for(Departamento d: departamentos) {
            if (d.getNome().equals(nome)) {
                return d;
            }
        }
        return null;
    }

    public Departamento getDepartamentoId(String id) {
        for(Departamento d: departamentos) {
            if (d.getId().equals(id)) {
                return d;
            }
        }
        return null;
    }

    public void removeDepartamentoNome(String nome) {
        for(Departamento d: departamentos) {
            if (d.getNome().equals(nome)) {
                this.departamentos.remove(d);
                break;
            }
        }
    }

    public void removeDepartamentoId(String id) {
        for(Departamento d: departamentos) {
            if (d.getId().equals(id)) {
                this.departamentos.remove(d);
                break;
            }
        }
    }

    public int getSize() {
        return this.departamentos.size();
    }

}
